﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

namespace ERPStore.NewsLetters.Workflows.Activities
{

	public sealed class CreatePendingItem : CodeActivity
	{
		public InArgument<ERPStore.NewsLetters.Models.EmailRecipient> EmailRecipient { get; set; }
		public InArgument<ERPStore.NewsLetters.Models.Campaign> Campaign { get; set; }
		public InArgument<DateTime> StartDate { get; set; }
		public OutArgument<ERPStore.NewsLetters.Models.PendingItem> PendingItem { get; set; }

		protected override void Execute(CodeActivityContext context)
		{
			var emailRecipient = context.GetValue(this.EmailRecipient);
			var campaign = context.GetValue(this.Campaign);
			var startDate = context.GetValue(this.StartDate);

			var pendingItem = new ERPStore.NewsLetters.Models.PendingItem();
			pendingItem.CampaignId = campaign.Id;
			pendingItem.CreationDate = DateTime.Now;
			pendingItem.ScheduledStartDate = startDate;
			pendingItem.EmailRecipientId = emailRecipient.Id;

			context.SetValue(this.PendingItem, pendingItem);
		}
	}
}
